Skip to content

Flag JVM-wide interning and escape-analysis-defeating shortcuts (AI perf review) - #13596

Draft
dougqh wants to merge 3 commits into
masterfrom
dougqh/perf-review-intern
Draft

dougqh wants to merge 3 commits into
masterfrom
dougqh/perf-review-intern

Conversation

@dougqh

@dougqh dougqh commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds two checks to the AI perf review:

  • J15 (memory): flags String.intern(), and Jackson's JsonFactory.Feature.INTERN_FIELD_NAMES (on by default), when they're applied to text read from input: a configuration, a payload, a header or a parsed document.
  • J16 (allocation): flags two "optimizations" that make escape analysis keep a short-lived object it would otherwise remove:
    • returning a shared sentinel (an empty iterator, a cached result) on some paths and a fresh object on others;
    • a hot traversal over an immutable collection that inherits AbstractList's or AbstractCollection's iterator, isEmpty() or forEach.

Motivation

The JVM's string table outlives the parse, so interned input stays for the life of the process:

  • Memory: the table grows with the input's cardinality, so high-cardinality input grows it without a bound the tracer controls.
  • Data: it can retain customer data that should die with the parse, such as targeting ids or user names.

dd-openfeature hit this: Jackson's default interned flag keys, variation keys and the keys of JSON values from its configuration. #13553 turns it off and shares strings per parse instead.

Why J16: both look like wins and aren't.

  • A shared sentinel makes the result a merge of "new" and "existing" objects, and C2 won't scalar-replace a merged allocation, so the fresh object becomes a real allocation on the common path too.
  • Inherited bytecode shares one profile across every subclass in the application, so its size()/get() calls go megamorphic and the iterator escapes. A quiet benchmark JVM hides this.
  • Measured on Store feature flag configuration lists and maps at their exact size (FFE optimization) #13556's configuration lists with the shared list profile polluted first: an inherited iterator cost 160 B and about 5× per walk. PrintInlining showed AbstractList$Itr's size() and get() as virtual calls, and a class with its own iterator inlined everything. In evaluations it was up to +174% time and +66 KB per evaluation, and the fix matched master's bytes.
  • The check is a judgment about the returned object's lifetime. Sharing a long-lived object, or one that escapes anyway, is still a win.

Additional Notes

  • Severity: SEV-2 for request or payload data (unbounded cardinality), SEV-3 for configuration. Literals and small closed sets of names are exempt, since the JVM interns literals anyway.
  • Fix it points to: per-parse sharing, a canonicalizing table dropped when the parse returns, and INTERN_FIELD_NAMES off on the JsonFactory. It doesn't name a toolbox class yet; a per-parse StringCanonicalizer is proposed in Add a bounded, per-parse StringCanonicalizer to the toolbox (FFE optimization) #13588, and the remedies list can point to it once that merges.
  • Numbered J15 and J16 because J14 is the product-off check.

Contributor Checklist

🤖 Generated with Claude Code

String.intern() and Jackson's INTERN_FIELD_NAMES, on by default, put text
read from input in the JVM's string table, which outlives the parse: it
grows with the input's cardinality and can retain customer data. J15
flags it and points to per-parse sharing instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core type: documentation tag: performance Performance related changes tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM labels Nov 20, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.00 s 13.96 s [-0.3%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 13.01 s 13.03 s [-0.8%; +0.5%] (no difference)
startup:petclinic:appsec:Agent 17.77 s 17.66 s [-0.1%; +1.4%] (no difference)
startup:petclinic:iast:Agent 17.46 s 17.29 s [-3.4%; +5.3%] (no difference)
startup:petclinic:profiling:Agent 17.51 s 17.42 s [-0.7%; +1.7%] (no difference)
startup:petclinic:sca:Agent 17.39 s 17.59 s [-5.5%; +3.3%] (no difference)
startup:petclinic:tracing:Agent 16.31 s 16.85 s [-7.3%; +0.9%] (no difference)

Commit: 32073dce · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

J16: returning a shared sentinel (an empty iterator, a cached result) on
some paths makes the result a merged allocation C2 won't scalar-replace,
and inheriting AbstractList's iterator, isEmpty or forEach for a hot
traversal shares a profile that goes megamorphic in an application. Both
keep short-lived objects escape analysis would otherwise remove. The check
asks the reviewer to judge the returned object's lifetime: sharing a
long-lived object is still a win.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh changed the title Flag JVM-wide interning of parsed input (AI perf review) Flag JVM-wide interning and escape-analysis-defeating shortcuts (AI perf review) Nov 21, 2026
EscapeShapeBenchmark measures the shared-sentinel, two-allocation and
null merges across JDKs, including mergeWithNull, which allocates until
JDK 21+ and so still matters on Java 8. Maybe is the worked example of
the single-construction-site discipline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes tag: performance Performance related changes type: documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant